class TagUser < ActiveRecord::Migration
  def self.up
    create_table :tags_users do |t|
      t.column :tag_id, :integer, :null => false
      t.column :user_id, :integer, :null => false
    end
    add_index :tags_users, [:tag_id, :user_id], :unique
    remove_column :tags, :user_id
    change_column :images_tags, :image_id, :integer, :default => 0
    change_column  :images_tags, :tag_id, :integer, :default => 0
  end

  def self.down
    drop_table :tags_users
    add_column :tags, :user_id, :integer,  :null => false
    change_column :images_tags, :image_id, :string, :null => false
    change_column  :images_tags, :tag_id, :string, :null => false
  end
end
